import {Component, Input, OnInit} from '@angular/core';
import {RightRoleResourse} from "../../../../model/RightRoleResourse";
import {ManageService} from "../../../../services/manage.service";
import {AlertService} from "../../../../services/alert.service";

@Component({
  selector: 'app-zyzcedit',
  templateUrl: './zyzcedit.component.html',
  styleUrls: ['./zyzcedit.component.css']
})
export class ZyzceditComponent implements OnInit {
  @Input() id: string
  @Input() opreationtype: string
  @Input() type: string
  r: RightRoleResourse

  constructor(private manageService: ManageService,
              private alertService: AlertService) {
    this.r = new RightRoleResourse()
  }

  ngOnInit(): void {
    console.log(this.type)
    if (this.opreationtype == "update") {
      this.getRoleResourceByid()
    }else{
      if(this.type=='A'){
        this.type="ACTION"
        this.r.pid = this.id
        this.r.type = this.type
      }else{
        this.type="MENU"
        this.r.pid = this.id
        this.r.type = this.type
      }

    }
  }

  getRoleResourceByid() {
    this.manageService.getRightresourceByid(this.id).then((data: any) => {
      if (data.msg == "ok") {
        this.r = data.obj
      } else {
        this.alertService.showError("根据id查询菜单失败")
      }
    })
  }

  save() {

    this.manageService.saveRightresource(this.r).then((data: any) => {
      if (data.msg == "ok") {
        this.alertService.showSuccess("设置菜单成功")
      } else {
        this.alertService.showError("设置菜单失败")
      }
    })
  }
}
